<%@page import="jpa.entities.Item"%>
<%@page import="jpa.entities.ItemType"%>
<%@page import="jpa.entities.Revision"%>
<jsp:useBean id="user" class="jsp.classes.Session" scope="session"/>
<%
    long p = Long.parseLong(request.getParameter("p"));
    Item i = user.findProjectById(p).getRootFolder().findItemById(Long.parseLong(request.getParameter("id")));
%>
<p class="Title2" style="margin-right: 100px;">Details</p>
<form>
    <input type="text" class="inputField" name="title" value="<%=i.getTitle()%>"/>
    <input type="text" class="inputField" name="shortDesc" value="<%=i.getShortDescription()%>"/>
    <textarea name="longDesc" class="usersListbox" rows="8"><%=i.getLongDescription()%></textarea>
    <textarea name="changeLog" class="usersListbox" rows="8">changelog.... nog doen dus</textarea>
    <a href="javascript: document.profile.submit()" class="uploadButton"><div class="uploadButton"><p class="centerText">SAVE</p></div></a>
    <br/><br/>
</form>
<%if (i.getType() == ItemType.FOLDER) {%>
<p>Upload a file to this folder</p>
<form enctype="multipart/form-data" method="post" name="uploadForm" action="upload">
    <input type="hidden" name="dir" value="<%=i.getId()%>"/>
    <input type="hidden" name="project" value="<%=p%>"/>
    <table>
        <tbody>
            <tr>
                <td>Title</td>
                <td>
                    <input type="text" class="inputField" name="title"/>
                </td>
            </tr>
            <tr>
                <td>Short description</td>
                <td>
                    <input type="text" class="inputField" name="shortdescription"/>
                </td>
            </tr>
            <tr>
                <td>Long description</td>
                <td>
                    <textarea name="longdescription" class="usersListbox" rows="8"></textarea>
                </td>
            </tr>
            <tr>
                <td>ChangeLog</td>
                <td>
                    <textarea name="changelog" class="usersListbox" rows="8"></textarea>
                </td>
            </tr>
            <tr>
                <td>File</td>
                <td>
                    <input name="file" class="inputField" style="width:100%" type="file">
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <!--<input type="submit" value="Upload File">-->
                    <a href="javascript: document.uploadForm.submit()" class="uploadButton"><div class="uploadButton"><p class="centerText">Upload</p></div></a>
                </td>
            </tr>
        </tbody>
    </table>
</form>
<%} else {%>
<p>New revision</p>
<form enctype="multipart/form-data" method="post" name="newRevisionForm" action="upload">
    <input type="hidden" name="item" value="<%=i.getId()%>"/>
    <input type="hidden" name="project" value="<%=p%>"/>
    <textarea name="changeLog" class="usersListbox" rows="8">changelog.. Verplicht!</textarea>
    <input name="file" type="file">
    <a href="javascript: document.newRevisionForm.submit()" class="uploadButton"><div class="uploadButton"><p class="centerText">Upload</p></div></a>
</form>
<%
        for (int j = 1; j <= i.getLatestRevision(); j++) {
            Revision r = i.getRevision(j);
            out.print("<div>" + j + ": <a href=\"javascript:download(" + p + "," + i.getId() + "," + j + ")\">" + r.getFilename() + "</a></div>");
        }
    }
%>
